<?php
use yii\grid\GridView;
use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '模块列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="modularity-index">

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            [
                'class' => 'yii\grid\DataColumn',
                'label' => '标识',
                'value' => function ($module) {
                    return $module['id'];
                },
            ],
            [
                'class' => 'yii\grid\DataColumn',
                'label' => '名称',
                'value' => function ($module) {
                    return $module['instance']->name;
                }
            ],
            [
                'class' => 'yii\grid\DataColumn',
                'label' => '描述',
                'value' => function ($module) {
                    return $module['instance']->description;
                }
            ],
            [
                'class' => 'yii\grid\DataColumn',
                'label' => '版本',
                'value' => function ($module) {
                    return $module['instance']->version;
                }
            ],

            [
                'class' => 'yii\grid\Column',
                'header' => '作者',
                'content' => function ($module) {
                    return Html::mailto($module['instance']->author, $module['instance']->author_email);
                }
            ],
            [
                'class' => 'yii\grid\DataColumn',
                'label' => '依赖',
                'value' => function ($module) {
                    return $module['instance']->requireModules;
                }
            ],
            [
                'class' => 'yii\grid\Column',
                'content' => function ($module) {
                    $content = '';
                    if($module['instance']->is_system)
                    {
                        $content .= ' 系统内置 ';
                    }
                    else if($module['can_install']){
                        $content .= Html::a(' 安装 ',['install','id'=>$module['id']]);
                    }
                    else
                    {
                        if($module['has_backend'])
                        {
                            if($module['can_active_backend'])
                            {
                                $content .= Html::a(' 启用后台 ',['active','id'=>$module['id'],'app' => 'backend']);
                            }
                            else
                            {
                                $content .= Html::a(' 关闭后台 ',['deactive','id'=>$module['id'],'app' => 'backend']);
                            }
                        }
                        if($module['has_frontend'])
                        {
                            if($module['can_active_frontend'])
                            {
                                $content .=  Html::a(' 启用前台 ',['active','id'=>$module['id'],'app' => 'frontend']);
                            }
                            else
                            {
                                $content .= Html::a(' 关闭前台 ',['deactive','id'=>$module['id'],'app' => 'frontend']);
                            }
                        }
                        if($module['has_api'])
                        {
                            if($module['can_active_api'])
                            {
                                $content .= Html::a(' 启用接口 ',['active','id'=>$module['id'],'app' => 'api']);
                            }
                            else
                            {
                                $content .= Html::a(' 关闭接口 ',['deactive','id'=>$module['id'],'app' => 'api']);
                            }
                        }
                        if($module['can_uninstall'])
                        {
                            $content .= Html::a(' 卸载 ',['uninstall','id'=>$module['id']]);
                        }
                    }
                    return $content;
                }
            ],
        ]
    ]);
    ?>

</div>
